package c2.advanced.business.demo;

import c2.advanced.business.base.AdvancedDaoTemplate;
import c2.advanced.business.demo.po.DemoBook;
import c2.advanced.share.DbFacade;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public class DemoDao extends AdvancedDaoTemplate {

    public DemoDao(DbFacade root) {
        super(root);
    }

    /** 查找指定类型的书 */
    public List<DemoBook> findBooksByType(String type) {
        return mongo().find(Query.query(Criteria.where("type").is(type)), DemoBook.class);
    }

    /** 根据唯一ID找到指定的书 */
    public DemoBook getBook(int uid) {
        return mongo().findById(uid, DemoBook.class);
    }
}
